﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace YXShop.TemplateAction
{
    public partial class LabelParse
    {
        /// <summary>
        /// FS:LabelType=Other标签处理函数
        /// </summary>
        /// <returns></returns>
        public string OtherProduct()
        {
            string reStr = string.Empty;
            string mystyle = this.Label_Inserted;
            string str_Option = this.GetParamValue("YX:Option");
            YXShop.BLL.Product.ProductInfo pibll = new YXShop.BLL.Product.ProductInfo();
            YXShop.Model.Product.ProductInfo pimodel = null;
            if (!string.IsNullOrEmpty(str_Option))
            {
                YXShop.Common.SysParameter sp = new YXShop.Common.SysParameter();
                switch (str_Option)
                {
                    #region 商品详细页位置导航
                    case "ProductNav":
                        string ProID = ChangeHope.WebPage.PageRequest.GetQueryString("q_productid");
                        if (!string.IsNullOrEmpty(ProID) || ProID != null)
                        {
                            if (ChangeHope.Common.ValidateHelper.IsNumber(ProID))
                            {

                                YXShop.BLL.Product.ProductInfo productbll = new YXShop.BLL.Product.ProductInfo();
                                YXShop.Model.Product.ProductInfo productmodel = productbll.GetModel(Convert.ToInt32(ProID));
                                if (productmodel != null)
                                {
                                    if (productmodel.pro_CID != string.Empty)
                                    {
                                        YXShop.BLL.Product.Productclass productclassbll = new YXShop.BLL.Product.Productclass();
                                        YXShop.Model.Product.Productclass productclassmodel = productclassbll.GetModelID(Convert.ToInt32(productmodel.pro_CID));
                                        if (productclassmodel != null)
                                        {
                                            string[] strCID = productclassmodel.Parentpath.Split(',') ;
                                            string str = string.Empty;
                                            string url = string.Empty;
                                            url = Common.UrlStr("productlist", "q_cid=" + productclassmodel.ID + "", "product/");
                                            str = ">> <a href=\"" + url + "\">" + productclassmodel.Name + "</a> ";
                                            for (int i = 1; i < strCID.Length - 1; i++)
                                            {
                                                productclassmodel = productclassbll.GetModelID(Convert.ToInt32(strCID[i]));
                                                if (productclassmodel != null)
                                                {
                                                    url = Common.UrlStr("productlist", "q_cid=" + productclassmodel.ID + "", "product/");
                                                    reStr += ">> <a href=\"" + url + "\">" + productclassmodel.Name + "</a> ";
                                                }
                                            }
                                            reStr += str;
                                        }
                                    }
                                }
                            }
                        }
                        break;
                    #endregion

                    #region 商品分类位置导航
                    case "ProductClassNav":
                        string ProductClassID = ChangeHope.WebPage.PageRequest.GetString("q_cid");
                        string endProductClassName=string.Empty;
                        if (ProductClassID != "")
                        {
                            YXShop.BLL.Product.Productclass pcbll = new YXShop.BLL.Product.Productclass();
                            YXShop.Model.Product.Productclass pcmodel = pcbll.GetModelID(Convert.ToInt32(ProductClassID));
                            if (pcmodel != null)
                            {
                                string[] strParentPath = pcmodel.Parentpath.Split(',');
                                endProductClassName = pcmodel.Name;
                                for (int f = 1; f < strParentPath.Length - 1; f++)
                                {
                                    pcmodel = pcbll.GetModelID(Convert.ToInt32(Convert.ToInt32(strParentPath[f])));
                                    if (pcmodel != null)
                                    {
                                       string url = Common.UrlStr("productlist", "q_cid=" + pcmodel.ID + "", "product/");
                                        reStr += ">> <a href=\"" + url + "\">" + pcmodel.Name + "</a> ";
                                    }
                                }
                            }
                        }
                        reStr += endProductClassName;
                        break;

                    #endregion

                    #region 商品优化
                    case "ProductMetaKeyWords":
                        string mkwproductid = ChangeHope.WebPage.PageRequest.GetQueryString("q_productid");
                        if (mkwproductid != "")
                        {
                            pimodel = pibll.GetModel(Convert.ToInt32(mkwproductid));
                            if (pimodel != null)
                            {
                                if (pimodel.pro_MetaKeywords != string.Empty)
                                {
                                    reStr = pimodel.pro_MetaKeywords;
                                }
                                else
                                {
                                    reStr = pimodel.pro_Name;
                                }
                            }
                        }
                        break;
                    case "ProductMetaDescription":
                        string mdproductid = ChangeHope.WebPage.PageRequest.GetQueryString("q_productid");
                        if (mdproductid != "")
                        {
                            pimodel = pibll.GetModel(Convert.ToInt32(mdproductid));
                            if (pimodel != null)
                            {
                                if (pimodel.pro_MetaDescription != string.Empty)
                                {
                                    reStr = pimodel.pro_MetaDescription;
                                }
                                else
                                {
                                    reStr = pimodel.pro_Name;
                                }
                            }
                        }
                        break;
                    case "ProductMetaTitle":
                        string mtproductid = ChangeHope.WebPage.PageRequest.GetQueryString("q_productid");
                        if (mtproductid != "")
                        {
                            pimodel = pibll.GetModel(Convert.ToInt32(mtproductid));
                            if (pimodel != null)
                            {
                                if (pimodel.pro_MetaTitle != string.Empty)
                                {
                                    reStr = pimodel.pro_MetaTitle;
                                }
                                else
                                {
                                    reStr = pimodel.pro_Name;
                                }
                            }
                        }
                        break;
                    #endregion

                    #region 商品相册
                    case "ProductAlbum":
                        int ShowCount = 6;
                        StringBuilder shtml = new StringBuilder();
                        string productalbunID =ChangeHope.WebPage.PageRequest.GetQueryString("id");
                        YXShop.BLL.Product.ProductAlbum pabll=new YXShop.BLL.Product.ProductAlbum();
                        System.Data.DataTable dt = pabll.GetProAlbumAll(Convert.ToInt32(productalbunID),-1,0);
                        YXShop.BLL.Product.ProductInfo datab = new YXShop.BLL.Product.ProductInfo();
                        YXShop.Model.Product.ProductInfo modelpi = datab.GetModel(Convert.ToInt32(productalbunID));
                        shtml.Append("<div id=\"Show1\">");
                        int d = 0, k = 2, c = 0;
                        bool Estimate = false;
                        if (modelpi!=null)
                        {
                            shtml.Append("<img src=\"" + sp.DummyPaht +  modelpi.pro_Images + "\" name=\"" + c + "||" + sp.DummyPaht + "" + modelpi.pro_Original + "\" width='80' height='46'/>&nbsp;");
                            Estimate = true;
                            c++;
                        }

                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            shtml.Append("<img src=\"" + sp.DummyPaht + "" + dt.Rows[i]["thumbnailaddress"].ToString() + "\" name=\"" + c + "||" + sp.DummyPaht + "" + dt.Rows[i]["originaladdress"].ToString() + "\" width='80' height='46'/>&nbsp;");
                            d++;
                            c++;
                            if (Estimate)
                            {
                                int sc = ShowCount - 1;
                                if (d % sc == 0)
                                {
                                    shtml.Append("</div><div id=\"Show" + k + "\" style='display:none'>");
                                    k++;
                                    Estimate = false;
                                    d++;
                                }

                            }
                            else
                            {
                                if (d % ShowCount == 0)
                                {
                                    shtml.Append("</div><div id=\"Show" + k + "\" style='display:none'>");
                                    k++;
                                }
                            }


                        }
                        shtml.Append("<input name=\"tCounts\" id=\"tCounts\" type=\"hidden\" value=\"" + (k - 1) + "\" /></div>");
                        return shtml.ToString();
                        break;
                    #endregion
                }
            }
            return reStr;
        }
    }
}
